// 路由定义
const routePath = {
  "index": "/pages/index/index",
  "logs": "/pages/logs/logs"
};
// tabbar名单 特殊处理
const tabbar = ['index', 'service']

export default {
  // 参数转换
  parse: function (data) {
    if (!data) return '';
    let tempArr = [];
    for (let key in data) {
      tempArr.push(`${key}=${encodeURIComponent(data[key])}`);
    }
    return '?' + tempArr.join('&');
  },
  go: function (path = 'index', params = null, duration = 0) {
    setTimeout(() => {
      const isTabbar = tabbar.indexOf(path) == -1;
      // 如果是tabbar用switchTab方法切换
      wx[isTabbar ? 'navigateTo' : 'switchTab']({
        url: routePath[path] + this.parse(params),
      })
    }, duration * 1000);
  },
  goBack: function (delta = 1, duration) {
    setTimeout(() => {
      wx.navigateBack({ delta })
    }, duration * 1000)
  }
}